from django.db import models

# Create your models here.

class Product(models.Model):
    name = models.CharField(verbose_name='产品名称', max_length=32)
    desc = models.CharField(verbose_name='产品描述', max_length=128)
    icon = models.ImageField(verbose_name='产品图标', upload_to='product/')

    class Meta:
        verbose_name = '产品大类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class ProductInstance(models.Model):
    name = models.CharField(verbose_name='具体产品名称', max_length=32)
    main_img = models.ImageField(verbose_name='产品主图')
    type = models.CharField(verbose_name='产品类型', choices=( ('bulk', '散装'), ('gift', '礼盒') ), max_length=4)
    product = models.ForeignKey(verbose_name='是什么产品', to=Product)
    detail = models.TextField(verbose_name='产品详情文章')

    class Meta:
        verbose_name = '具体产品'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class SlaveImages(models.Model):
    desc = models.CharField(verbose_name='图片描述', max_length=128)
    img = models.ImageField(verbose_name='图片')
    pi = models.ForeignKey(to=ProductInstance, verbose_name='谁的图片')

    class Meta:
        verbose_name = '产品附图'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.desc